<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据类型</title>
    <script>
        function f1() {
            // number类型
            let id = 1;
            console.log(typeof id);
            id = 3.14;
            console.log(typeof id);
            // string类型
            let name = "admin";
            console.log(typeof name);
            name = "1";
            console.log(typeof name);
            name = "true";
            console.log(typeof name);
            // boolean类型
            let flag = true;
            console.log(typeof flag);
            flag = false;
            console.log(typeof flag);
        }

        function f2() {
            // 纯对象类型
            let obj = new Object();
            console.log(typeof obj);
            // 数组类型,数组类型本质上也是object
            let arr = [1, 2, 3];
            console.log(arr);
            console.log(typeof arr);
            // 日期类型,本质上也是object
            let date = new Date();
            console.log(date);
            console.log(typeof date);
            // 函数类型,function类型
            let fn = f3;
            console.log(typeof fn);
            fn = function () {
                console.log("匿名函数");
            }
            console.log(typeof fn);

            // 该方式不是函数类型,而是去执行f3方法
            // 将方法返回值赋值给变量fn
            fn = f3();
            console.log(fn);
            console.log(typeof fn);
        }

        function f3() {
            console.log("这是f3方法");
            let a = null;
            let b;
            let c = NaN; // Not a Number
            console.log(typeof a); // object
            console.log(typeof b); // undefined,声明了变量后没有给变量赋值
            console.log(typeof c); // number,将一个字符串转换数字失败
            let d = "a";
            d = parseInt(a);
            console.log(d);
            return "f3";
        }
    </script>
</head>
<body>
<button onclick="f1()">基本数据类型</button>
<br>
<button onclick="f2()">复合数据类型</button>
<br>
<button onclick="f3()">非正常类型</button>
</body>
</html>